<style src="./index.scss" lang="scss" scoped rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
    export default {
        mixins: [Vue.prototype.$vFN.Mixins.Base],
        components: {
            SelectAddress: async () => Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectAddress())
        },
        computed: {},
        data() {
            return {
                appWindow: window,
                item: null,
                title: "修改收货地址",
                form: {
                    mobile: "",
                    name: "",
                    // 详细地址
                    detailAddress: "",
                    // 省
                    province: '',
                    provinceCode: '',

                    // 市
                    city: '',
                    cityCode: '',

                    // 区
                    region: '',
                    regionCode: '',

                    // 街
                    street: '',
                    streetCode: ''
                },
                // 窗口显示
                boxVisible: false,



            };
        },
        methods: {

            // 选择地址
            async selectAddressChange() {
                console.error(await this.validate());
            },
            // 验证 
            validate() {
                return new Promise((resolve, reject) => {
                    this.$refs["editForm"].validate((valid) => {
                        valid ? resolve(true) : resolve(false)
                    });
                });
            },
            // 提交
            async submit() {
                if (!await this.validate()) {
                    return
                }
                let _d = {
                    ...this.form,
                };
                _d.orderId = this.item.id
                let _data = await this.$vFN.Http.post({
                    url: "mall-site-portal/order/modifyReceiveAddress",
                    data: _d,
                },window);
                if (_data._ok) {
                    this.$vFN.Tools.messageSuccess("操作成功");
                    this.editBoxClose();
                    this.onSuccess();
                }
            },
            // 成功回调
            onSuccess() {},
            // 取消回调
            onCancel() {},
            // 失败回调
            onError() {},
            // 关闭窗口
            editBoxClose() {
                this.boxVisible = false;
            },
            // 取消
            editBoxCancel() {
                this.editBoxClose();
            },

            show(e, item) {
                console.log(e, item);
            }
        },
        watch: {},
        async mounted() {
            if (this.item.orderReceiveAddress) {
                for (let i in this.form) {
                    this.form[i] = this.item.orderReceiveAddress[i]
                }
                
            }
            this.boxVisible = true;

        },
        beforeCreate() {},
    };
</script>